package Process8;

import java.util.concurrent.Semaphore;

public class SemaphoreTest {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore=new Semaphore(0);
        for(int i=0;i<10;i++){
            final int j=i;
            Thread t = new Thread() {
                @Override
                public void run() {
                    try {
                        System.out.println(j);
                    } finally {
                        semaphore.release();
                    }
                }
            };
            t.start();
        }
        semaphore.acquire(10);
        System.out.println("main");
    }
}
